package com.wolfking.converter.rowmapper;

import com.google.common.collect.Maps;
import com.wolfking.converter.transform.FieldTransform;
import com.wolfking.converter.util.FieldConverterUtil;

import java.util.Map;

@SuppressWarnings("all")
public class DefaultFieldRowMapper<T> extends AbstractCamelRowMapper<T> {

    private Class<T> aClass;
    private Map<String, FieldTransform<?>> fieldTransformMap;

    public DefaultFieldRowMapper(Class<?> aClass) {
        this.aClass = (Class<T>) aClass;
        fieldTransformMap = Maps.newHashMap();
    }

    public DefaultFieldRowMapper(Class<?> aClass, Map<String, FieldTransform<?>> fieldTransformMap) {
        this.aClass = (Class<T>) aClass;
        this.fieldTransformMap = fieldTransformMap;
    }

    @Override
    protected T convertMapToObject(Map<String, Object> map) {
        return FieldConverterUtil.assemblyObjectIgnoreException(map, this.aClass, fieldTransformMap);
    }
}
